let ycmjGame = require('../../data/YcmjGame');
cc.Class({
    extends: cc.Component,

    properties: {
        num:cc.Node
    },
    start () {
        this.tid = '';
    },
    enterNum(e,c){
        cc.log('enterNum--length-->',this.tid.length);
        if(this.tid.length === 6) return; 
        this.tid += c;
        let index = this.tid.length - 1;
        this.num.getChildByName('label_'+index).getChildByName('num_'+index).getComponent(cc.Label).string = c;
        if(this.tid.length == 6){
            let tid = parseInt(this.tid);
            pomelo.request('hall.hallHandler.joinRoom',{tid:tid},function(res){
                if(res.code != -5 && res.code != 500){
                    console.log('res.msg----hall.hallHandler.joinRoom->',res.msg);
                    let curgame = ycmjGame.getInstance(res.msg);
                    if(curgame){
                        game.curGame = curgame;
                        cc.director.loadScene('Ycmj');
                    };
                }else{

                }
            });
        }
    },
    deleteNum(e,c){
        if(this.tid.length == 0) return;
        let index = this.tid.length - 1;
        this.num.getChildByName('label_'+index).getChildByName('num_'+index).getComponent(cc.Label).string = '';
        this.tid = this.tid.substring(0,this.tid.length -1);
        cc.log('enterNum---->',this.tid); 
    },
    resetNum(e,c){
        if(this.tid.length == 0) return;
        this.tid = '';
        for(let i=0;i<6;i++){
            this.num.getChildByName('label_'+i).getChildByName('num_'+i).getComponent(cc.Label).string = '';
        };
    },
    back_btn(){
        this.node.destroy();
    }
    // update (dt) {},
});
